const msqlFile = require('../assets/js/commnMySQL');
const connection = msqlFile.sqlConnection;

module.exports = {
  getCommentsByPage(pageIndex,pageSize,callback){
    let offset = (pageIndex - 1)*pageSize;
    let sql = `SELECT comments.id,author,comments.content,title,comments.created,comments.\`status\`
    FROM comments
    JOIN posts ON comments.post_id=posts.id
    LIMIT ${offset},${pageSize}`;
    connection.query(sql,(err,result)=>{
        callback(err,result);
    });
  },
  getCommentsTotal(callback){
    let sql = `SELECT COUNT(*) as total FROM comments`;
    connection.query(sql,(err,result)=>{
      callback(err,result);
    });
  }
};